﻿using System.Collections.Generic;
using System.ComponentModel;

namespace System.Lua.Converters
{
    internal static class LuaTypeDescriptor
    {
        private static readonly Dictionary<Type, ILuaTypeConverter> CustomTypeConverters = new Dictionary<Type, ILuaTypeConverter>
                                                                                       {
                                                                                           { typeof(Boolean), new BooleanConverter() },
                                                                                           { typeof(DateTime), new PosixDateTimeConverter() },
//                                                                                         { typeof(String), new StringConverter() }
                                                                                       };

        public static ILuaTypeConverter GetConverter(Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            return CustomTypeConverters.ContainsKey(type) ?
                   CustomTypeConverters[type] : new LuaTypeConverter(TypeDescriptor.GetConverter(type));
        }

        public static ILuaTypeConverter GetConverter(object component)
        {
            if (component == null)
                throw new ArgumentNullException("component");

            return LuaTypeDescriptor.GetConverter(component.GetType());
        }
    }
}
